package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.SalesPromotionBean.MyTopic;
import com.lidroid.xutils.BitmapUtils;

public class PromotionBaseAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<MyTopic> arrayList;

	public PromotionBaseAdapter(Context context, ArrayList<MyTopic> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.sale_promotion_item,
					null);
			holder.home2_name = (TextView) convertView
					.findViewById(R.id.home2_name);
			holder.home2_pic = (ImageView) convertView
					.findViewById(R.id.home2_pic);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.home2_name.setText(arrayList.get(position).getName());
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils.display(holder.home2_pic, arrayList.get(position).getPic());
		return convertView;
	}

	class ViewHolder {
		TextView home2_name;
		ImageView home2_pic;
	}

}
